#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <signal.h>
#include <sys/epoll.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <string.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <stddef.h>
#include <linux/types.h>

/**
 *  i2capp w "1234"
 *  i2capp r 
*/
int main(int argc,char **argv)
{ 
    int fd = 0;
    int ret = 0;
    char buf[32] = {0};
    int len = 0;

    fd = open("/dev/at24c02", O_RDWR);
    if (fd < 0) {
        printf("open failed errno=%d\n", errno);
        printf("%s\n", strerror(errno)); 
        return -1;
    }

    if (argv[1][0] == 'w') {
        len = strlen(argv[2]);
        printf("led=%d\n", len);

        ret = write(fd, argv[2], len);
        if (ret < 0) {
            printf("write failed errno=%d\n", errno);
            printf("%s\n", strerror(errno));
            return -1;
        }
    } else if (argv[1][0] == 'r') {
        ret = read(fd, buf, sizeof(buf));
        if (ret < 0) {
            printf("read failed errno=%d\n", errno);
            printf("%s\n", strerror(errno));
            return -1;
        }

        printf("Get Data:%s\n", buf);
    }

    close(fd);

    return 0;
}